<template>
	<view class="content">
		<nav-bars title="收支明细" isBack backColor="#fff" color="#fff" background="#333333"></nav-bars>

		<view class="main">
			<view v-if="viewList.length == 0" style="line-height: 200rpx; margin-top: 30rpx;color: #999;text-align: center;">暂无收支明细</view>
			<view class="row-wrap" v-else>
				<!-- <view class="date">
					2121年10月
				</view> -->
				<view class="form-item" v-for="(item,index) in viewList" :key="index">
					<view class="sidebar_a">
						<text>
							订单编号:
						</text>
						<text>
							{{item.relationsn}}
						</text>
						<view class="dateTime">
							<text>{{getFormatDate(item.create_time*1000,'MM-dd hh:mm')}}</text>
						</view>
					</view>
					<view class="sidebar_b" v-if="item.type=='cash_in'">
						<text>+</text>
						<text>{{item.amount}}</text>
						元
					</view>
					<view class="sidebar_b" v-else>
						<text>-</text>
						<text>{{item.amount}}</text>
						元
					</view>
				</view>
			</view>
			
		</view>
	</view>
</template>

<script>
	import service_enter from '@/service/enter.js'
	export default {
		data() {
			return {
                statusLoading: 'loadmore',
				iconType: 'flower',
				loadText: {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '实在没有了~'
				},
				baseImg:this.$static,
				navHeight:200,
				canPrice:0,
				params: {
					year: true,
					month: true,
					day: false,
					hour: false,
					minute: false,
					second: false
				},
				showTime:false,
				viewList:[],
				year:new Date().getFullYear(),
				month:new Date().getMonth()+1<10?'0'+(new Date().getMonth()+1):new Date().getMonth()+1,
				page:1,
				pagesize:10
			}
		},
		onLoad(options) {
            this.getViewAll()
		},
		onReachBottom() {
					this.page++
					let params = {
						page:this.page,
						pagesize:this.pagesize
					}
					service_enter.viewAll(params).then(res=>{
						console.log(res,'查看明细')
						if(res.code==1){
							if(!res.data.list.list.length){
								this.statusLoading = 'nomore'
							}else{
								this.statusLoading = 'loading'
							}
							this.canPrice = res.data.list.income_sum?res.data.list.income_sum:0.00;
							this.viewList = this.viewList.concat(res.data.list.list)
						}
					})
				},
		methods: {
			// 获取格式化日期
			getFormatDate(t, fmt = 'yyyy-MM-dd') {
				let time = t instanceof Date ? t : new Date(typeof t === 'string' ? t.replace(/\-/g, "/") : t)
				if (time instanceof Date && !isNaN(time.getTime())) {
					let o = {
						'M+': time.getMonth() + 1,
						'd+': time.getDate(),
						'h+': time.getHours(),
						'm+': time.getMinutes(),
						's+': time.getSeconds()
					}
					if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (time.getFullYear() + "").substr(4 - RegExp.$1.length))
					for (var k in o) {
						if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)))
					}
					return fmt
				}
				else {
					return 'NaN'
				}
			},
			// 获取明细
			getViewAll(){
				this.page = 1
				uni.showLoading({
					title:'加载中...'
				})
				let params = {
					page:this.page,
					pagesize:this.pagesize
				}
				service_enter.viewAll(params).then(res=>{
					console.log(res,'查看明细')
					if(res.code==1){
						if(res.data.list.list.length<10){
							this.statusLoading = 'nomore'
						}
						this.canPrice = res.data.list.income_sum?res.data.list.income_sum:0.00
						this.viewList = res.data.list.list?res.data.list.list:[]
					}
				})
				uni.hideLoading()
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 100%;

		.main {
			margin-top: 60rpx;

			.row-wrap {
				padding: 0rpx 30rpx 84rpx 30rpx;
			}

			.date {
				width: auto;
				height: 60rpx;
				font-size: 32rpx;
				font-weight: bold;
				color: #643613;
				line-height: 60rpx;
			}

			.form-item {
				color: #242424;
				padding:20rpx 0;
                 position: relative;
				.dateTime {
					padding-top: 20rpx;
					color: #515152;
					font-size: 24rpx;
				}

				.sidebar_b {
					position: absolute;
					right:0;
					bottom:15rpx;
					font-size: 28rpx;
					text {
						color: #DC7D3D;
						font-size: 38rpx;
						font-weight: bold;
						margin-right: 8rpx;
					}
				}
			}
		}
	}
</style>
